package vip.liux.contracts.security;

import org.springframework.security.core.Authentication;

import java.util.Optional;

public class AuthenticationKit {

    public static Optional<Object> getPrincipal(Authentication authentication) {
        return Optional.ofNullable(authentication).map(Authentication::getPrincipal);
    }

    public static Optional<Object> getCredentials(Authentication authentication) {
        return Optional.ofNullable(authentication).map(Authentication::getCredentials);
    }

    public static Optional<String> getName(Authentication authentication) {
        return Optional.ofNullable(authentication).map(Authentication::getName);
    }

    public static Optional<String> getPrincipalStr(Authentication authentication) {
        return getPrincipal(authentication).map(Object::toString);
    }

    public static Optional<String> getCredentialsStr(Authentication authentication) {
        return getCredentials(authentication).map(Object::toString);
    }
}
